package org.lql.algo.codecrush.week009.question.type.III;

import org.lql.algo.common.TreeNode;

/**
 * @author: liangqinglong
 * @date: 2025-08-20 17:02
 * @description: 226. 翻转二叉树 <a href="https://leetcode.cn/problems/invert-binary-tree/description/">...</a>
 **/
public class InvertTree {

	public TreeNode invertTree(TreeNode root) {
		if ( root == null){
			return null;
		}
		TreeNode temp = root.left;
		root.left = root.right;
		root.right = temp;
		invertTree(root.left);
		invertTree(root.right);
		return root;
	}

	public static void main(String[] args) {
		TreeNode root = new TreeNode(4);
		root.left = new TreeNode(2);
		root.right = new TreeNode(7);
		root.left.left = new TreeNode(1);
		root.left.right = new TreeNode(3);
		root.right.left = new TreeNode(6);
		root.right.right = new TreeNode(9);
		InvertTree invertTree = new InvertTree();
		TreeNode invert = invertTree.invertTree(root);
		System.out.println(invert);
	}
}
